home *** CD-ROM | disk | FTP | other *** search
- // 'Craps' game by David Scouten
- // 1993 DAS Software Publications
-
- #include <conio.h>
- #include <dos.h>
- #include <iostream.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
-
- int two_dice(int,int,int,int,char[]);
- void display_results(int,int,int);
- FILE *infptr, *outfptr;
-
- void main()
- {//begin main program
-
- int gamestats, sum, point, dis1, dis2, win=0, lose=0;
- int bet, money=100;
-
- clrscr();
- cout<<"\nCraps by David Scouten";
- cout<<"\n1993 DAS Software Publications\n";
- cout<<"\nDisplay just dice (y/n) ? ";
- if (getche()=='y') //begin if
- dis1 = 1;
- else //else
- dis1 = 0;
- // end if
- cout<<"\nDisplay just totals (y/n) ? ";
- if (getche()=='y') //begin if
- dis2 = 1;
- else //else
- dis2 = 0;
- //end if
- cout<<"\nLoad game ? (y/n): ";
- if (getche()=='y') // begin if
- goto LOADGAME;
- else // else
- goto INBET;
- // end if
-
- PLAYAGAIN:
-
- if (money<=0) {//begin if
- win=0; lose=0; money=100;
- }//end if
-
- INBET:
- clrscr();
- display_results(win,lose,money);
- cout<<"\nEntering '0' will quit game";
- cout<<"\nWhat is your bet ? ";
- cin>>bet;
- if (bet>money) {//begin if
- cout<<"\nYou don't have enough!";
- goto INBET;
- }//else if
- else if (bet<=0) {
- goto ENDGAME;
- }//end if
-
- srand(clock());
- cout<<"\n";
- sum = two_dice(6,100,dis1,dis2,"Player rolled: ");
- cout<<"\n";
-
- switch (sum) {//begin case switch
-
- case 7: case 11:
- gamestats = 1;
- break;
- case 2: case 3: case 12:
- gamestats = 2;
- break;
- default:
- gamestats = 0;
- point = sum;
- cout<<"Point is "<<point<<"\n\n";
- break;
- }//end switch
- while (gamestats == 0) {//begin while
- sum = two_dice(6,100,dis1,dis2,"Player rolled: ");
- cout<<"\n";
-
- if (sum == point) {//begin if
- cout<<"You made Point!\n";
- gamestats = 1;
- } else if (sum == 7) {//else if
- gamestats = 2;
- }//end if
- }//end while
- if (gamestats == 1) {//begin if
- cout<<"\nPlayer wins";
- win+=1; money+=bet;
- }
- else //else
- {
- cout<<"\nPlayer loses";
- lose+=1; money-=bet;
- }//end if
-
- display_results(win,lose,money);
- if (money<=0) {//begin if
- cout<<"\nYou have no more money!";
- cout<<"\nPlay again (y/n) ? ";
- if (getche()=='y') {//begin if
- clrscr();
- goto PLAYAGAIN;
- }
- else //else
- {
- cout<<"\n";
- goto ENDGAME;
- }//end if
- }//end if
-
- cout<<"\nSave game ? (y/n): ";
- if (getche()=='y') //begin if
- goto SAVEGAME;
- else // else
- goto INBET;
- // end if
-
- SAVEGAME:
- if ((outfptr=fopen("craps.dat","w"))==NULL) {//check for data file
- cout<<"Error opening 'craps.dat' file.\n";
- }//end if
- fprintf(outfptr,"%d %d %d",win,lose,money);
- fclose(outfptr);
- goto INBET;
-
- LOADGAME:
- if ((infptr=fopen("craps.dat","r"))==NULL) {//check for data file
- cout<<"Error opening 'craps.dat' file.\n";
- }//end if
- fscanf(infptr,"%d %d %d",&win,&lose,&money);
- fclose(infptr);
- goto INBET;
-
- ENDGAME:
- cout<<"\nSee ya' later!";
- }//end main program
-